home *** CD-ROM | disk | FTP | other *** search
- /*
-
- This is a C++ source code fragment for the LCIS function
- described in the SIGGRAPH'99 paper
-
- "LCIS: A Boundary Hierarchy For Detail-Preserving Contrast Reduction"
- ----------------------------------------------------------------------
- by Jack Tumblin and Greg Turk.
-
-
- I offer this code only as an aid to people who may want to implement LCIS
- themselves. This code was written to test and explore LCIS easily, not for
- speed or efficiency. You may notice that the 'leakfix' and 'diffusion'
- passes through the image could be combined to cut code size almost in half,
- and that the code is full of expensive sqrt() calls and seemingly pointless
- casts between PIXTYPE and double etc.; these are vestiges of earlier
- experiments. Though it is not elegant, it is readable and easy to debug.
- Please use, share and modify this code in any way you wish.
-
- A few items in the code may need some explanation:
-
- --'Raw2D' and 'Raw3D' are my own floating-point image classes whose pixel
- datatype is set by '#DEFINE PIXTYPE float'. Both hold resizeable
- arrays of pixels; Raw2D holds a 2D array indexed by (x,y),
- and Raw3D holds a 1D array of Raw2D objects, indexed by 'z'.
- In the code below, Raw3D objects all hold three Raw2D objects.
-
- member functions you'll see here include:
- get(x,y) -- returns the PIXTYPE pixel value at (x,y)
- put(x,y,val) -- write PIXTYPE value
- sizer(arg) -- set array size to match 'arg'
- wipecopy(src) -- copy contents of 'src', resize as needed.
- ones() -- set every pixel value to 1.0
- zeros() -- set every pixel value to 0.0
-
- --LCIS inputs:
- The input image read from:
- m_pA --a pointer to a Raw3D image object; it holds 3 Raw2D
- objects, and we'll use the middle one of three.
- To read input pixel value at (x,y), do this:
- val = m_pA->get(x,y,1);
-
- Several user-settable parameters are held in a dialog box class;
- these are:
- --# of timesteps to run: found at m_pParamDlg->m_diffusCount
- --Conductance Threshold 'K'; found at m_pParamDlg->m_diffusKval
- --Timestep length 'T'; found at m_pParamDlg->m_diffusTstep
- --Leakfix enable/disable found at M_pParamDlg->m_diffusLeakfix
-
- --LCIS outputs:
- the output image is written to:
- m_pOut --a pointer to a Raw3D object; it holds 3 Raw2D objects;
- two hold the current value for 'leakfix multipliers'
- (D_E,D_N in the paper), the other holds the result
- of the LCIS operation.
- m_pOut->z[0] holds the EW leakfix multiplier,
- m_pOut->z[1] holds the LCIS output image,
- m_pOut->z[2] holds the NS leakfix multipler.
-
- --Quick overview:
- We begin by copying the input image to the output image object;
- we never touch the input object again. After initializing a few
- pesky details, the LCIS code below uses just a few image objects:
- 'src','bound' and 'm_pOut' (the output image object).
-
- The 'src' object holds the result of the most recently completed
- timestep; we use 'src' as the source of all pixel information we need
- as we compute results of the current timestep and write them to m_pOut.
- (m_pOut and src also hold the values of the leakfix multipliers for
- each pixel). Once we finish finding all new pixel values for m_pOut,
- we copy m_pOut to src and start on the next timestep.
-
- For each timestep there are two passes through the entire image;
- The first pass computes the 'leakfix multiplier' value for each
- link, and determines whether or not the link has become a 'boundary
- link'. If it has, we mark the pixels on either end of the link as
- a 'boundary pixel' by setting its value in the Raw2D image object
- called 'bound' to the value IS_BOUND_PIX.
-
- The second pass computes the flux through all links and applies the
- flux to the output image m_pOut. However, it does not compute or
- apply any flux at all through any link with a boundary pixel on
- either end. This accomplishes two goals:
- --no flux will ever transform a ridge-like shock into a step-like
- shock (prohibited by the LCIS PDEs--see dissertation for proof)
- --no curvature estimate will use pixels that straddle a shock,
- where curvature is (theoretically) infinite.
-
- If I've still failed to make this code clear to you and you're still
- interested, send me a question by e-mail: ccsupjt@cc.gatech.edu;
- if this is obsolete (I'm finally leaving Georgia Tech this fall) then
- search the web for my website--I'll be there somewhere.
-
- Regards,
- --Jack Tumblin
- */
-
-
-
-
- //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789_
- //
- BOOL CFcnGroup::fcnLCIS4(CString & label)
- //------------------------------------------------------------------------------
- // Low Curvature Image Simplifier(LCIS)
- //
- // K, timestep, leakfix enable, # iterations,
- // from SetFcnParam dialog class.
- //
- //------------------------------------------------------------------------------
- // --prevents any curvature or motive force est. from using a set of pixels
- // that straddles a 'shock', and
- // --ensures that a 'shock' always forms a ridge discontinuity that never
- // (due to smoothing within a region) evolves into a step discontinuity,
- // mimicking the behavior of the PDE form of LCIS.
- // Heres how:
- // --DEFINE: any pixel on either end of a link that contains a shock is a
- // 'Boundary Pixel', (shock==leakfix multiplier is >10.0)
- // --APPLY: any link CONNECTED to a boundary pixel must have ZERO FLUX to
- // ensure the boundary pixel will not change.
- // Note that this scheme ADIABATIC and fully consistent with the
- // continuous PDE form of LCIS.
- //------------------------------------------------------------------------------
- // (Return 1 if successful; retn 0 if text 'label' does not match our internal
- // name for this function; this is a double-check that index# used to select
- // functions matches the desired function)
- {
- Raw2D src; // source img for each diffusion timestep.
- Raw2D bound; // boundary-pixel map.
-
- int i,iE1,iE2,iW,j,jN1,jN2,jS,k,imax,jmax,kmax; // image indices
- PIXTYPE N2val,N1val,Pval,S1val,W1val,E1val,E2val,NEval,NWval,SEval;
- // neighborhood pixels: north,south,..
- // (See LCIS paper, Figure 6)
- PIXTYPE Pxx2,Pyy2,Exx2,Eyy2,Nxx2,Nyy2,Nxy2,Sxy2,Wxy2;
- // 2nd